[#ftl]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加参数</title>
<link rel="stylesheet" type="text/css" href="${base}/css/date.css" />
<link rel="stylesheet" type="text/css" href="${base}/css/base.css" />
<link rel="stylesheet" type="text/css" href="${base}/css/form.css" />
<link rel="stylesheet" type="text/css" href="${base}/css/pop.css" />


<script type="text/javascript" src="${base}/commonjs/jquery1.7.2/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="${base}/commonjs/jquery-forms.js"></script>
<script type="text/javascript" src="${base}/commonjs/message/message.js"></script>
<script type="text/javascript" src="${base}/commonjs/noty/jquery.noty.packaged.min.js"></script>
<script type="text/javascript" src="${base}/commonjs/jquery-validation/jquery.validate.min.js" ></script>
<script type="text/javascript" src="${base}/commonjs/jquery-validation/localization/messages_zh.js" ></script>
<script type="text/javascript" src="${base}/commonjs/tab/tabs.js"></script>
<script type="text/javascript" src="${base}/commonjs/datatable/js/jquery.dataTables.min.js"></script>
<script type="text/javascript">	
$(document).ready(function(){
	var dictId=$("#beanId").val();
	var tag=0;
	 var table = $('#itemTable').DataTable( {
	     "language": {
            "infoEmpty": "没有找到任何数据项。",
            "zeroRecords":"没有找到匹配的记录",
            "search": "过滤"
        },
	    "paging":   false,
        "ordering": false,
        "info":     false,
        "filter":   false,
        "columnDefs": [  {
            "targets": 4,
            "data": null,
            "defaultContent": "<button>Delete</button>"
        } ]
    });
    $('#itemTable tbody').on( 'click', 'button', function () {   
        table.$('tr.selected').removeClass('selected');
        $(this).parents('tr').addClass('selected');   
        table.row('.selected').remove().draw( false );
        $("#aname").val("");
	    $("#acode").val("");
	    $("#avalue").val("");
	    $("#ashowOrder").val("");
    } );
    
    $('#itemTable tbody').on( 'dblclick', 'tr', function () {
            table.$('tr.selected').removeClass('selected');
            $(this).addClass('selected');
            $("#aname").val($(this).find("td").eq(0).html());
		    $("#acode").val($(this).find("td").eq(1).html());
		    $("#avalue").val($(this).find("td").eq(2).html());
		    $("#ashowOrder").val($(this).find("td").eq(3).html());
            tag=1;
    } );
	
//增加一行
    $('#addItem').on( 'click', function () {
        var aname=$("#aname").val();
	    var acode=$("#acode").val();
	    var avalue=$("#avalue").val();
	    var ashowOrder=$("#ashowOrder").val();
	    if(tag==1){
	    table.row('.selected').remove().draw( false );
	    tag=0;
	    }
        table.row.add( [
            aname,
            acode,
            avalue,
            ashowOrder
        ] ).draw();
       $("#aname").val("");
	    $("#acode").val("");
	    $("#avalue").val("");
	    $("#ashowOrder").val("");         
    } );    
});
  function updateItem(param){
        $("#aname").val(param[0]);
        alert($("#aname").val());
        alert(param);
	    $("#acode").val(param[1]);
	    $("#avalue").val(param[2]);
	    $("#ashowOrder").val(param[3]);
  }
  
  
</script>

<script type="text/javascript"> 
$(function() {
            var names=[];
            var codes=[];
            var values=[];
            var showOrders=[];
        
            $("#butSave").click(function(){
               var dt= $('#itemTable').DataTable(); 
                $("#itemTable tbody tr").each(function()
                 {
                  names.push($(this).find("td").eq(0).html());
                  codes.push($(this).find("td").eq(1).html());
                  values.push($(this).find("td").eq(2).html());
                  showOrders.push($(this).find("td").eq(3).html());
                 });
                     $("#dataform").submit();           
                 });
        
                var v = jQuery("#dataform").validate({
                 submitHandler: function(form) {
                    $(form).ajaxSubmit({
                        url:"${base}/system/dictionary/add",
                        data:{"names":names,
                        "codes":codes,
                        "values":values,
                        "showOrders":showOrders
                        },
                        success: function(data){  
                                noty({
                                  text:extendMessages(data).msg.message,
                                  layout:"center",
                                  timeout:2000,
                                  callback:{
                                     afterClose:function(){
                                                  window.parent.location.reload();   
                                                }
                                   }
                                });
                       }
                    });
                }
         });
        $("#butCancel").click(function(){
            window.parent.closeArtDialog();
        });
        
 });    
</script>
</head>
<body>
<!-- 主体开始 -->
<div class="dataForm">
		<div class="eva_content_top">
			<ul id="eva_all">
				<li><a tab="eva_tab1" class="eva_focus" href="javascript:void(0);">基本信息</a></li>
				<li><a tab="eva_tab2" class="white" href="javascript:void(0);">数据项</a></li>
			</ul>
		</div>
		<div id="eva_tab1" class="eva_tab">
			<form id="dataform" action="add" method="post">
				<div class="content mt10">
					<dl>
					<dt><span   class="required">*</span>名称</dt>
					<dd>			
					<input  class="required " name="name" id="name"  type="text" />
					</dd>
					
					<dt><span   class="required">*</span>代码</dt>
					<dd>			
					<input  class="required " name="code" id="code"  type="text"  />
					</dd>

					<dt>数据类型</dt>
					<dd>			
					[@c.select id="datatype"  attributes='class="clear"' datas="common.datatype" /]
					</dd>
					<dt>描述</dt>
					<dd>
						<textarea rows="5" cols="38" id="description" name="description" ></textarea>
					</dd>
					<dl>
					<div class="clear"></div>
				</div>
				<div class="pop_btn">
					<input type="button" id="butSave" class="btn_1" value="保存"/>
					<input type="button" id="butCancel" class="btn_1" value="取消"/>
			    </div>
			</form>						
		</div>
		<div id="eva_tab2" class="eva_tab">
		       <form id="itemform" action="add" method="post">
				<div class="content mt10">
				<input  id="dictId" name="dictId"   type="hidden"  value="${dictid!''}"/>
					<dl>
					<dt>名称</dt>
					<dd>			
					<input  name="aname" id="aname"  type="text" />
					</dd>
					
					<dt>代码</dt>
					<dd>			
					<input  name="acode" id="acode"  type="text"  />
					</dd>

					<dt>值</dt>
					<dd>
						<input  name="avalue" id="avalue"  type="text"  />
					</dd>
					<dt>次序</dt>
					<dd><input   name="ashowOrder" id="ashowOrder"  type="text"  />
					</dd>
					<div class="clear"></div>
				</div>
				<div class="">
					<input type="button" id="addItem" class="btn_1" value="保存"/>
			    </div>
			</form>
				<div class="userole">
					<dl>			
				   
					   <table id="itemTable" class="mt10 ml10 date_add" style="width:100%;">
							   <thead>
									<tr >	
										<th class="color_2 tab_bt">
										名称										
										</th>
										<th class="color_2 tab_bt">
										键值										
										</th>
										<th class="color_2 tab_bt">
										值										
										</th>
										<th class="color_2 tab_bt">
										次序										
										</th>
										<th class="color_2 tab_bt">
										操作										
										</th>										
									</tr>
							
							  </thead>
							</table>
					</dt>					
					<dl>
				</div>				
		</div>				
</div>

</body>
</html>